﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using IBLL;
using BLLImp;
using PageEntity;

namespace OASystem.Controllers
{
    public class SysActionController : BaseController
    {
        ISysActionServer sysActionServer;
        public SysActionController()
        {
            sysActionServer = new SysActionServer();

        }

        //
        // GET: /SysAction/

        public ActionResult Index()
        {
            SetTheme();
            return View();
        }
        public ActionResult ListView(PagerDTO pager)
        {
            DataGridDTO model = sysActionServer.LoadSysActionForPage(pager);
            return Json(model);

        }
        [HttpGet]
        public ActionResult Add()
        {
            return PartialView();
        }
        [HttpPost]
        public ActionResult Add(SysActionDTO mode)
        {
            MyJsonResult result = new MyJsonResult();
            try
            {

                sysActionServer.Save(mode);
                result.Result = true;
                result.Obj = mode;
                return Json(result, "text/html", JsonRequestBehavior.AllowGet);

            }
            catch (System.Data.Entity.Validation.DbEntityValidationException e)
            {

                result.Result = false;
                return Json(result, "text/html", JsonRequestBehavior.AllowGet); ;
            }

        }
        public ActionResult Delet(long SysActionID)
        {
            if (this.Request.IsAjaxRequest())
            {
                if (SysActionID <= 0) return Json(new MyJsonResult() { Result = false });
                var result = sysActionServer.Delet(new SysActionDTO() { SysActionID = SysActionID });
                return Json(new MyJsonResult() { Result = result });

            }
            else
            {
                return RedirectToAction("Index");
            }
        }
    }
}
